package com.ruoyi.parking.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.parking.domain.SmartParkingSpace;
import com.ruoyi.parking.service.ISmartParkingSpaceService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 停车位Controller
 * 
 * @author ruoyi
 * @date 2025-03-21
 */
@RestController
@RequestMapping("/space")
public class SmartParkingSpaceController extends BaseController
{
    @Autowired
    private ISmartParkingSpaceService smartParkingSpaceService;

    /**
     * 查询停车位列表
     */
    @RequiresPermissions("parking:space:list")
    @GetMapping("/list")
    public TableDataInfo list(SmartParkingSpace smartParkingSpace)
    {
        startPage();
        List<SmartParkingSpace> list = smartParkingSpaceService.selectSmartParkingSpaceList(smartParkingSpace);
        return getDataTable(list);
    }

    /**
     * 查询停车位列表
     */
    @GetMapping("/listByArea")
    public TableDataInfo listByArea(Integer scAreaId)
    {
        List<SmartParkingSpace> list = smartParkingSpaceService.selectSmartParkingSpaceListByArea(scAreaId);
        return getDataTable(list);
    }

    /**
     * 导出停车位列表
     */
    @RequiresPermissions("parking:space:export")
    @Log(title = "停车位", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SmartParkingSpace smartParkingSpace)
    {
        List<SmartParkingSpace> list = smartParkingSpaceService.selectSmartParkingSpaceList(smartParkingSpace);
        ExcelUtil<SmartParkingSpace> util = new ExcelUtil<SmartParkingSpace>(SmartParkingSpace.class);
        util.exportExcel(response, list, "停车位数据");
    }

    /**
     * 获取停车位详细信息
     */
    @RequiresPermissions("parking:space:query")
    @GetMapping(value = "/{scSpaceId}")
    public AjaxResult getInfo(@PathVariable("scSpaceId") Integer scSpaceId)
    {
        return success(smartParkingSpaceService.selectSmartParkingSpaceByScSpaceId(scSpaceId));
    }

    /**
     * 新增停车位
     */
    @RequiresPermissions("parking:space:add")
    @Log(title = "停车位", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SmartParkingSpace smartParkingSpace)
    {
        return toAjax(smartParkingSpaceService.insertSmartParkingSpace(smartParkingSpace));
    }

    /**
     * 修改停车位
     */
    @RequiresPermissions("parking:space:edit")
    @Log(title = "停车位", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SmartParkingSpace smartParkingSpace)
    {
        return toAjax(smartParkingSpaceService.updateSmartParkingSpace(smartParkingSpace));
    }

    /**
     * 删除停车位
     */
    @RequiresPermissions("parking:space:remove")
    @Log(title = "停车位", businessType = BusinessType.DELETE)
	@DeleteMapping("/{scSpaceIds}")
    public AjaxResult remove(@PathVariable Integer[] scSpaceIds)
    {
        return toAjax(smartParkingSpaceService.deleteSmartParkingSpaceByScSpaceIds(scSpaceIds));
    }

    /**
     * 查询停车位列表
     */
    @GetMapping("/querySpaceByCar")
    public TableDataInfo querySpaceByCar(String scLicensePlate)
    {
        List<SmartParkingSpace> list = smartParkingSpaceService.selectSmartParkingSpaceByCar(scLicensePlate);
        return getDataTable(list);
    }
}
